//
//  UIBarButtonItem+Extension.swift
//  新浪微博
//
//  Created by 胡不归是大虾 on 16/9/22.
//  Copyright © 2016年 胡不归是大虾. All rights reserved.
//

import UIKit
extension UIBarButtonItem {
    //添加构造方法
    convenience init(imageName:String? = nil, action:Selector, target:Any, title:String = "") {
        //实例化一个按钮
        let btn = UIButton()
        if imageName != nil {
            
            btn.setImage(UIImage(named: imageName!), for: .normal)
            btn.setImage(UIImage(named: imageName! + "_highlighted"), for: .highlighted)
        }
        btn.setTitle(title, for: .normal)
        btn.setTitleColor(UIColor.darkGray, for: .normal)
        btn.setTitleColor(UIColor.orange, for: .highlighted)
        btn.titleLabel?.font = UIFont.systemFont(ofSize: 17)
        btn.sizeToFit()
        btn .addTarget(target, action: action, for: .touchUpInside)
        self.init( )
        self.customView = btn
    }
}
